
#ifndef IAP2INTERFACE_H
#define IAP2INTERFACE_H

#ifdef  __cplusplus
extern "C" {
#endif

#include <stdio.h>
#include <stdint.h>
#include <libusb.h>

#include "DebugServices.h"

#define kiAP2TransportType_Unknown      0
#define kiAP2TransportType_HostUsb      1
#define kiAP2TransportType_DeviceUsb    2
#define kiAP2TransportType_Bluetooth    3
#define kiAP2TransportType_WiFi         4
#define kiAP2TransportType_HIDG         5

extern int  giAP2TransportType;
extern char gDeviceId[ 18 ];        // deviceID of the device.
extern int  gWireConflictWireless;

//===========================================================================================================================
//	CarPlay2iAP2InterfaceDelegate
//===========================================================================================================================

typedef void    (*CarPlay2iAP2InterfaceCarPlayStartBonjour_f)();
typedef void    (*CarPlay2iAP2InterfaceSendiAPMessage_f)( int length, const unsigned char * ptr );
typedef int     (*CarPlay2iAP2InterfaceStartAirPlayServer_f)();
typedef void    (*CarPlay2iAP2InterfaceStopAirPlayServer_f)();
typedef int     (*CarPlay2iAP2InterfaceCarPlayControllerContainsCString_f)( const char * inDeviceID );
typedef int     (*CarPlay2iAP2InterfaceCarPlayControllerEqual_f)();
typedef void    (*CarPlay2iAP2InterfaceEnd_f)();
typedef void    (*CarPlay2iAP2InterfacePublishSharkBonjour_f)();
typedef void    (*CarPlay2iAP2InterfaceIdentificationInfo_f)();
typedef void    (*CarPlay2iAP2InterfaceRequestSharkDeviceId_f)(unsigned char *data, int len);
typedef void    (*CarPlay2iAP2InterfaceRequestSharkLibusb_f)(int operate);
typedef void    (*CarPlay2iAP2InterfaceRequestSharkLocationInfo_f)(char *data);
typedef void    (*CarPlay2iAP2InterfaceUsbVidPid_f)(void * vid , void * pid);
typedef void    (*CarPlay2iAP2InterfaceCallEvent_f)(int keyCode , int keyAction);
typedef void    (*CarPlay2iAP2InterfaceStartHID_f)(const unsigned char *data , int len);
typedef void    (*CarPlay2iAP2InterfaceHIDReport_f)(const unsigned char *data, int len);
typedef void    (*CarPlay2iAP2InterfaceWifiInfo_f)(const void *data);
typedef void    (*CarPlay2iAP2InterfaceHttpInfoReport_f)(void *ipAddress, int port,void * srcVersion,void * deviceID,void * publicKey);

/**
 * 请求向accessory发送数据
 *
 */
typedef int (*CarPlay2iAP2InterfaceWrite_f)(int /*handle*/,signed char * /*data*/, signed short /*len*/,int */*length*/);

/**
 * 请求向accessory读取数据
 *
 */
typedef int (*CarPlay2iAP2InterfaceRead_f)(int /*handle*/,signed char * /*data*/, signed short /*len*/,int */*length*/);

typedef struct
{
    CarPlay2iAP2InterfaceCarPlayStartBonjour_f  carPlayStartBonjour_f;
    CarPlay2iAP2InterfaceSendiAPMessage_f       sendiAPMessage_f;
    CarPlay2iAP2InterfaceEnd_f                  end_f;
    CarPlay2iAP2InterfaceStartAirPlayServer_f   startAirPlayServer_f;
    CarPlay2iAP2InterfaceStopAirPlayServer_f    stopAirPlayServer_f;
    CarPlay2iAP2InterfaceCarPlayControllerContainsCString_f     controllerContainsCString_f;
    CarPlay2iAP2InterfaceCarPlayControllerEqual_f               controllerEqual_f;
    CarPlay2iAP2InterfaceRead_f               accessoryRead_f;
    CarPlay2iAP2InterfaceWrite_f              accessoryWrite_f;
    CarPlay2iAP2InterfacePublishSharkBonjour_f              publishSharkBonjour_f;
    CarPlay2iAP2InterfaceIdentificationInfo_f               accessoryIdentification_f;
    CarPlay2iAP2InterfaceRequestSharkDeviceId_f             requestSharkDeviceId_f;
    CarPlay2iAP2InterfaceRequestSharkLibusb_f               requestSharkLibusb_f;
    CarPlay2iAP2InterfaceRequestSharkLocationInfo_f         requestSharkLocationInfo_f;
    CarPlay2iAP2InterfaceUsbVidPid_f         				readUsbVidPid_f;
    CarPlay2iAP2InterfaceCallEvent_f         				onCallEvent_f;
    CarPlay2iAP2InterfaceStartHID_f         				accessoryStartHID_f;
    CarPlay2iAP2InterfaceHIDReport_f        				accessoryHIDReport_f;
    CarPlay2iAP2InterfaceWifiInfo_f        				    accessoryWifiInfo_f;
    CarPlay2iAP2InterfaceHttpInfoReport_f        		    accessoryHttpInfoReport_f;

} CarPlay2iAP2InterfaceDelegate;

#define CarPlay2iAP2InterfaceDelegateInit( PTR )	memset( (PTR), 0, sizeof( CarPlay2iAP2InterfaceDelegate ) );

void CarPlay2iAP2InterfaceSetDelegate( const CarPlay2iAP2InterfaceDelegate *inDelegate );

void    iAP2InterfaceInitial();
void    BonjourCarPlayAvailability();
int     _getBluetoothAddress( char * outAddress );
void    _sendWiFiData( const char *ptr, int length );
void    iAP2OverCarPlaySetup();

void    AirPlaySessionCreated();
void    AirPlaySessionFinalized();

void    AirPlaySessionControlDisableBluetooth();

OSStatus _GetUsbRoleStatus( char * outRoleStatus );

#ifdef  __cplusplus
}  
#endif
#endif //IAP2INTERFACE_H
